from pymysql import Connection

conn = None

try:
    conn = Connection(host='linux.server', port=3306, user='root', password='Chenhao$123456', database='db_pymysql')
    cursor = conn.cursor()
    sql = """
      select * from tb_user
    """
    cursor.execute(sql)
    # cursor.fetchall()返回的是二维元组
    user_list = cursor.fetchall()
    for row in user_list:
        print(row)
    cursor.close()

except Exception as e:
    print("error：", e)
finally:
    if conn:
        conn.close()
